import { ref, onMounted, onUnmounted } from 'vue'
import { throttle } from '@/utils/helpers'

export function useScroll() {
  const scrollY = ref(0)
  const isScrollingDown = ref(false)
  const isAtTop = ref(true)
  
  let lastScrollY = 0
  
  const handleScroll = throttle(() => {
    scrollY.value = window.scrollY
    isScrollingDown.value = scrollY.value > lastScrollY
    isAtTop.value = scrollY.value < 50
    lastScrollY = scrollY.value
  }, 100)
  
  onMounted(() => {
    window.addEventListener('scroll', handleScroll, { passive: true })
    handleScroll()
  })
  
  onUnmounted(() => {
    window.removeEventListener('scroll', handleScroll)
  })
  
  return {
    scrollY,
    isScrollingDown,
    isAtTop
  }
}

